/*-----------------------------------------------------------------
 * Econ	variables
 *
 */

#include "copyrite.h"
#include "config.h"
#include <string.h>
#include <strings.h>
#include <math.h>
#include "conf.h"
#include "externs.h"
#include "parse.h"
#include "confmagic.h"
#include "function.h"
#include "intrface.h"
#include "ansi.h"
#include "match.h"
#include "space.h"
#include "flags.h"
#include "dbdefs.h"
#include "mushdb.h"
#include "lock.h"
#include "dbdefs.h"
#include "attrib.h"
#include "log.h"
#include "econ.h"

int econ_ver = 1;
dbref econ_parent = ECON_PARENT;
dbref monitor_room = MONITOR_ROOM;
dbref bank_data	= BANK_DATA;
dbref commod_data = COMMOD_DATA;
dbref factory_data = FACTORY_DATA;
dbref market_data = MARKET_DATA;
dbref mine_data	= MINE_DATA;
dbref upg_data = UPG_DATA;
dbref ware_data	= WARE_DATA;
dbref econ_data = ECON_DATA;

int ware_space = WARE_SPACE;
int mine_space = MINE_SPACE;
int factory_space = FACTORY_SPACE;
int market_space = MARKET_SPACE;

const char *econ_errors[] = {
	"Undefined error",
	"No error",
	"Insufficent space on target",
	"Invalid parameter",
	"Closed",
	"Not enough commods in stock",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	"Not yet defined",
	""
};	

int do_get_referances (dbref executor, dbref ep) {
	
	ATTR *a;

	econ_parent = ep;
	
	/* MONITOR_ROOM */
	a = atr_get(ep,	MONITOR_ROOM_ATTR);
	if (a == NULL) {		
		return 0;
	} else {
		monitor_room = parse_dbref(atr_value(a));		
	}
	
	/* BANK_DATA */	       
	a = atr_get(ep,	BANK_DATA_ATTR);	
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,BANK_DATA_ATTR), 0);
		return 0;
	} else {
		bank_data = parse_dbref(atr_value(a));
	}

	/* COMMOD_DATA */
	a = atr_get(ep,	COMMOD_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,COMMOD_DATA_ATTR), 0);
		return 0;
	} else {
		commod_data = parse_dbref(atr_value(a));
	}
	
	/* FACTORY_DATA	*/
	a = atr_get(ep,	FACTORY_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,FACTORY_DATA_ATTR), 0);
		return 0;
	} else {
		factory_data = parse_dbref(atr_value(a));
	}
	
	/* MARKET_DATA */
	a = atr_get(ep,	MARKET_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,MARKET_DATA_ATTR), 0);
		return 0;
	} else {
		market_data = parse_dbref(atr_value(a));
	}
	
	/* MINE_DATA */
	a = atr_get(ep,	MINE_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,MINE_DATA_ATTR), 0);
		return 0;
	} else {
		mine_data = parse_dbref(atr_value(a));
	}
	
	/* UPG_DATA */
	a = atr_get(ep,	UPG_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,UPG_DATA_ATTR), 0);
		return 0;
	} else {
		upg_data = parse_dbref(atr_value(a));
	}
	
	/* WARE_DATA */
	a = atr_get(ep,	WARE_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,WARE_DATA_ATTR), 0);
		return 0;
	} else {
		ware_data = parse_dbref(atr_value(a));
	}
	
	/* ECON_DATA */
	a = atr_get(ep,	ECON_DATA_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,ECON_DATA_ATTR), 0);
		return 0;
	} else {
		econ_data = parse_dbref(atr_value(a));
	}
	
	/* WARE_SPACE */
	a = atr_get(ep,	WARE_SPACE_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,WARE_SPACE_ATTR), 0);
		return 0;
	} else {
		ware_space = parse_integer(atr_value(a));
	}
	
	/* MINE_SPACE */
	a = atr_get(ep,	MINE_SPACE_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,MINE_SPACE_ATTR), 0);
		return 0;
	} else {
		mine_space = parse_integer(atr_value(a));
	}
	
	/* MARKET_SPACE */
	a = atr_get(ep,	MARKET_SPACE_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,MARKET_SPACE_ATTR), 0);
		return 0;
	} else {
		market_space = parse_integer(atr_value(a));
	}
	
	/* FACTORY_SPACE */
	a = atr_get(ep,	FACTORY_SPACE_ATTR);
	if (a == NULL) {
		do_remit(1, unparse_dbref(monitor_room), tprintf("%s%s%s Problems reading %s.",ECON_ERR,ECON_ERR,ECON_ERR,FACTORY_SPACE_ATTR), 0);
		return 0;
	} else {
		factory_space = parse_integer(atr_value(a));
	}	
		
	return 1;
}	
